package me.caofeng.enums;


import org.springframework.http.MediaType;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.enums
 * @Description:
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-06-21 11:17
 * @Version: V1.0
 */
public enum MediaTypes {
    IMAGE(new String[]{
            MediaType.IMAGE_GIF_VALUE,
            MediaType.IMAGE_JPEG_VALUE,
            MediaType.IMAGE_PNG_VALUE
    });

    String[] types;

    MediaTypes() {
    }

    MediaTypes(String[] types) {
        this.types = types;
    }

    public String[] getTypes() {
        return types;
    }

    public void setTypes(String[] types) {
        this.types = types;
    }

    /**
     * @Author:曹峰 blog.caofeng.me
     * @Date: 2017/6/21 11:58
     * @Description: 判断类型是否匹配
    */
    public static boolean isMatched(MediaTypes mediaType, String type) {
        String[] types = mediaType.getTypes();
        for (String value : types){
            if (value.equals(type)){
                return true;
            }
        }

        return false;
    }
}
